/*
 * MemberManager.h
 *
 *  Created on: Mar 24, 2010
 *      Author: mike
 */

//*************************************************************************
// File Name: MemberManager.h
// Definition of MemberManager class - manages data from existing members.
// It can import files, modify member data to files, add new member(s)from
// file, display them, etc.
// "Group 3"
// CS 1C
// March 25, 2010
// Group Project: SuperWarehouse
// Due: March 25, 2010
// - KZ's comment
//*************************************************************************

#ifndef MEMBERMANAGER_H_
#define MEMBERMANAGER_H_

#include "MemberList.h"
#include "config.h"

/*
 * 	string memberName;
	int memberNumber;
	char memberType;
	time_t expirationDate;
	float annualDues;
	float totalSpent;

	.. totalRebate
 *
 */

class MemberManager {
public:

	struct MemberData {
		char name[CUSTOMERS_DATA_NAME_LENGTH];
		int number;
		char type;
		time_t expiration;
		float annualDues;
		float totalSpent;
		float totalRebate;
	};

	MemberManager();
	MemberManager(string dataFileName);
	virtual ~MemberManager();

	bool initialize();
	bool importMembersFromTextFile(string fileName);
	bool save();

	MemberList *getAllMembers();
	MemberList *getMembersByType(char memberType);
	MemberList *getSuperMembers();
	MemberList *getBasicMembers();
	MemberList *getExpiringMembers(time_t start, time_t end);


	void setDataFile(string fileName);
	string getDataFile();

	static MemberManager *instance();

private:
	static MemberManager *sharedInstance;
	string dataFile;
	MemberList *members;

	bool loadOrInitializeDataFile(string fileName);
	Member *createMemberFromData(MemberData *data);
	MemberData *createDataFromMember(Member *member);
	bool initializeDataFile(string fileName);
	bool writeMembersToDataFile(string fileName, MemberList *members);
	MemberList *readMembersFromDataFile(string fileName);

};

#endif /* MEMBERMANAGER_H_ */
